package com.kingint.web.sys.controller;


import com.kingint.mbg.dto.MemberParam;
import com.kingint.mbg.dto.MemberReturn;
import com.kingint.mbg.sys.entity.UmsMember;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.kingint.common.unitedresult.K;

import com.kingint.web.sys.service.UmsMemberService;



/**
 * @描述：会员表控制类
 * @作者: wxh
 * @日期: 2020-12-10
 */
@RestController
@RequestMapping("/umsMember")
@Api(value = "UmsMemberController", description = "会员表")
@CrossOrigin
public class UmsMemberController{

    @Autowired
    public UmsMemberService memberService;


    //微信小程序登录
    @ApiOperation(value = "微信小程序登录")
    @GetMapping(value = "/loginWxXiao")
    public Object loginWxXiao(@RequestParam(value = "code", required = false) String code,
                              @RequestParam(value = "encryptedData", required = false) String encryptedData,
                              @RequestParam(value = "iv", required = false) String iv) {
        Object o = memberService.loginByWeiXiao(code, encryptedData, iv);
        return K.ok().data(o);
    }


    @ApiOperation(value = "微信小程序手机登录")
    @RequestMapping(value = "/loginWithPhone", method = RequestMethod.POST)
    public Object loginWxXxiaoWithPhone(@RequestBody UmsMember umsMember) {
        return memberService.loginByWeiXiaoWithPhone(umsMember);
    }


    @ApiOperation("获取用户信息")
    @GetMapping("/user")//获取用户信息
    public Object user() {
        UmsMember umsMember = memberService.getUserInfo();
        return K.ok().data(umsMember);
    }

    @ApiOperation("修改手机号")
    @GetMapping("/modifyMobile")//获取用户信息
    public Object modifyMobile(MemberParam memberParam) {
        Integer i= memberService.modifyMobile(memberParam);
        if(i>0){
            return K.ok().data(i);
        }
        return K.error();
    }

    @ApiOperation("获取手机验证码")
    @GetMapping(value = "/getAuthCode")
    public Object getAuthCode(@RequestParam(value = "telephone") String telephone) {//1登录验证，2，修改验证3，注册验证
        return memberService.generateAuthCode(telephone);
    }

    //修改密码，个人邮箱，通讯地址

    @ApiOperation("修改密码，个人邮箱，通讯地址，头像，性别")
    @PostMapping("/changeUserInfo")//获取用户信息
    public Object changeUserInfo(@RequestBody MemberParam memberParam) {
        Integer i = memberService.changeUserInfo(memberParam);
        if(i>0){
            return K.ok().data(i);
        }
        return K.error();
    }

    @ApiOperation(value = "登出功能")
    @GetMapping(value = "/logout")
    public Object logout() {
        return K.ok();
    }
}